package dataBase;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UpdateDBTables {
	// We are aware of the code repetition but we need separate methods for all
	// of these.
	private static PreparedStatement statement;

	// create Barbarian
	public static void updateFoodOfBarbarian(Connection dbCon, String username)
			throws SQLException {
		statement = dbCon
				.prepareStatement("UPDATE users SET food = food - 150 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();

	}

	// create Archer
	public static void updateFoodOfArcher(Connection dbCon, String username)
			throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE users SET food = food - 300 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// create Wizard
	public static void updateFoodOfWizard(Connection dbCon, String username)
			throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE users SET food = food - 500 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// upgrade Barbarian
	public static void updateGoldWhenUpgradeBarbarianAtt(Connection dbCon,
			String username) throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE users SET gold = gold - 500 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	public static void updateGoldWhenUpgradeBarbarianHp(Connection dbCon,
			String username) throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE users SET gold = gold - 500 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// upgrade Archer
	public static void updateGoldWhenUpgradeArcherAtt(Connection dbCon,
			String username) throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE users SET gold = gold - 500 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	public static void updateGoldWhenUpgradeArcherHp(Connection dbCon,
			String username) throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE users SET gold = gold - 500 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// update Wizard
	public static void updateGoldWhenUpgradeWizardAtt(Connection dbCon,
			String username) throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE users SET gold = gold - 500 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	public static void updateGoldWhenUpgradeWizardHp(Connection dbCon,
			String username) throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE users SET gold = gold - 500 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// Update Army number
	public static void updateArmy(Connection dbCon, String username)
			throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE users SET army = army + 1 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// Update Army Capacity
	public static void updateArmyCapacity(Connection dbCon, String username,
			int armyCapacity) throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE users SET army_capacity = army_capacity + "
						+ armyCapacity
						+ " WHERE username LIKE '"
						+ username
						+ "'");
		statement.executeUpdate();
	}

	// Update Barbarian Count
	public static void updateBarbarianCount(Connection dbCon, String username)
			throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE HP_AD_LEVELS SET barbarians = barbarians + 1 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// Update Barbarian AD Level
	public static void updateBarbarianADLevel(Connection dbCon, String username)
			throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE HP_AD_LEVELS SET barbarianadlevel = barbarianadlevel + 1 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// Update Barbarian HP Level
	public static void updateBarbarianHPLevel(Connection dbCon, String username)
			throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE HP_AD_LEVELS SET barbarianhplevel = barbarianhplevel + 1 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// Update Archer Count
	public static void updateArcherCount(Connection dbCon, String username)
			throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE HP_AD_LEVELS SET archers = archers + 1 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// Update Archer AD Level
	public static void updateArcherADLevel(Connection dbCon, String username)
			throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE HP_AD_LEVELS SET archeradlevel = archeradlevel + 1 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// Update Archer HP Level
	public static void updateArcherHPLevel(Connection dbCon, String username)
			throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE HP_AD_LEVELS SET archerhplevel = archerhplevel + 1 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// Update Wizard Count
	public static void updateWizardCount(Connection dbCon, String username)
			throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("UPDATE HP_AD_LEVELS SET wizzards = wizzards + 1 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// Update Wizard AD Level
	public static void updateWizardADLevel(Connection dbCon, String username)
			throws SQLException {
		statement = dbCon
				.prepareStatement("UPDATE HP_AD_LEVELS SET wizzardadlevel = wizzardadlevel + 1 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// Update Wizard HP Level
	public static void updateWizardHPLevel(Connection dbCon, String username)
			throws SQLException {
		statement = dbCon
				.prepareStatement("UPDATE HP_AD_LEVELS SET wizzardhplevel = wizzardhplevel + 1 WHERE username LIKE '"
						+ username + "'");
		statement.executeUpdate();
	}

	// Update Gold Production
	public static void updateGoldProduction(Connection dbCon, String username,
			int goldProduction) throws SQLException {
		statement = dbCon
				.prepareStatement("UPDATE users SET gold_production = gold_production + "
						+ goldProduction
						+ " WHERE username LIKE '"
						+ username
						+ "'");
		statement.executeUpdate();
	}

	// Update Food Production
	public static void updateFoodProduction(Connection dbCon, String username,
			int foodProduction) throws SQLException {
		statement = dbCon
				.prepareStatement("UPDATE users SET food_production = food_production + "
						+ foodProduction
						+ " WHERE username LIKE '"
						+ username
						+ "'");
		statement.executeUpdate();
	}
}
